﻿
namespace TimeSheetReporting.Web.Service
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.Web.DomainServices;
    using System.Web.DomainServices.Providers;
    using System.Web.Ria;
    using System.Web.Ria.Services;
    using TimeSheetReporting.Web.Model;


    // Implements application logic using the TimeSheetDatabaseEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class TimeSheetService : LinqToEntitiesDomainService<TimeSheetDatabaseEntities>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Effort> GetEffort()
        {
            return this.ObjectContext.Effort;
        }

        public void InsertEffort(Effort effort)
        {
            this.ObjectContext.AddToEffort(effort);
        }

        public void UpdateEffort(Effort currentEffort)
        {
            if ((currentEffort.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentEffort, this.ChangeSet.GetOriginal(currentEffort));
            }
        }

        public void DeleteEffort(Effort effort)
        {
            if ((effort.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(effort);
            }
            this.ObjectContext.DeleteObject(effort);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Member> GetMember()
        {
            return this.ObjectContext.Member;
        }

        public void InsertMember(Member member)
        {
            this.ObjectContext.AddToMember(member);
        }

        public void UpdateMember(Member currentMember)
        {
            if ((currentMember.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentMember, this.ChangeSet.GetOriginal(currentMember));
            }
        }

        public void DeleteMember(Member member)
        {
            if ((member.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(member);
            }
            this.ObjectContext.DeleteObject(member);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Project> GetProject()
        {
            return this.ObjectContext.Project;
        }
    }
}


